<?php
//用户管理
namespace Home\Controller;
use Think\Controller;
class  UseradminController  extends Controller {
 public function _initialize(){
       if(empty($_SESSION['empid'])){
    


           
 $this->error('页面加载中。。。',U('Login/Login'),1);
    
       }
       
    }
    public function Userinfo(){
       


$User=M('SysUser');
$us=$User->select();
$this->assign('us',$us);
        $this->display();
       
        
    }
   public function Adduser(){
       
   if(IS_AJAX){
      
        $User=M('SysUser');
        $cf['empid']=I('post.empid');
        $tid=$User->where($cf)->find();
        if($tid){
            
           $data=3; 
        }else{
   $data['empid']=I('post.empid');
   $data['loginname']=I('post.loginname');
   $data['userlevel']=I('post.userlevel');
  $data['depart']=I('post.depart');
  $data['password']=MD5(888888);
            
   $add=$User->add($data);
        if($add){ 
            
           $data=0; 
        }    
        else{   $data=1; }}
        
        echo $data;
    }else{$this->display();}
        
    }
    
 public function Userxg(){
   $User=M('SysUser');
  
     
   if(IS_AJAX){
       $data['id']=I('post.id');
     $data['empid']=I('post.empid');
   $data['loginname']=I('post.loginname');
   $data['userlevel']=I('post.userlevel');
  $data['depart']=I('post.depart');
  if(!empty($_POST['password'])){
  $data['password']=MD5(I('post.password'));}
  $updata= $User->save($data); // 根据条件保存修改的数据    
  if($updata){
      
      $data=0;
  }else{
      
      $data=1;
  }
       echo $data;
       
   }else{
           
           $map['id']=I('get.id');
           $us= $User->where($map)->find();
           $this->assign('us',$us);
        $this->display();
        
   }           
     
     
 }
    
    
    public function del(){
      
        $map['id']=I('get.id');
      
        $User=M('SysUser');
    
        $del=$User->where($map)->delete();
        if($del){
            
          $this->success('删除成功');  
            
        }    else{
            
          $this->error('删除失败');  
            
        }

        
    } 

    //put your code here
}

